/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.GUI;

import br.ufg.inf.si.poo.formula1.Driver.Driver;
import br.ufg.inf.si.poo.formula1.Interface.InterfaceRegister;
import br.ufg.inf.si.poo.formula1.Library.Library;
import br.ufg.inf.si.poo.formula1.ManagementFiles.ManagementFilesSeason;
import br.ufg.inf.si.poo.formula1.Team.Team;
import java.text.ParseException;
import javax.swing.JOptionPane;

/**
 * ManageTeamsSeason
 *
 * Versao 1.0
 *
 * Data 16/02/2013
 *
 * @author Igor
 */
public class ManageTeamsSeason extends javax.swing.JInternalFrame implements InterfaceRegister {
    //Atributos
    private Team team;

    //Construtores
    /**
     * Creates new form FrameDefault
     */
    public ManageTeamsSeason() {
        initComponents();
        clearFields();
    }

    //Outros Metodos    
    /**
     * Exibe as equipes vinculadas no JList de equipes vinculadas
     */
    private void driversLinkedList(){
        String[] drivers = new String[4]; //Maximo de 4 pilotos por temporada
        //Lista Pilotos Vinculadas
        for(int i = 0;i < 4;i++){
            if(this.team.getDriver()[i] != null){
                drivers[i] = this.team.getDriver()[i].getDriverName();
            }
        }
        this.listPilotosVinculados.setListData(drivers);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTitulo = new javax.swing.JPanel();
        labelTitulo = new javax.swing.JLabel();
        panelDadosPrincipais = new javax.swing.JPanel();
        pageControlDadosEquipes = new javax.swing.JTabbedPane();
        tabPanelInformacoesEquipe = new javax.swing.JPanel();
        labelNomeCompleto = new javax.swing.JLabel();
        labelNome = new javax.swing.JLabel();
        labelDiretor = new javax.swing.JLabel();
        labelChefeTecnico = new javax.swing.JLabel();
        labelSede = new javax.swing.JLabel();
        labelPneus = new javax.swing.JLabel();
        labelChassi = new javax.swing.JLabel();
        labelMotor = new javax.swing.JLabel();
        labelPrimeiraTemporada = new javax.swing.JLabel();
        labelCampeaoMundialConstrutores = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida = new javax.swing.JLabel();
        labelPolePosition = new javax.swing.JLabel();
        labelVoltasMaisRapidas = new javax.swing.JLabel();
        labelPontos = new javax.swing.JLabel();
        labelNomeCompleto1 = new javax.swing.JLabel();
        labelNome1 = new javax.swing.JLabel();
        labelDiretor1 = new javax.swing.JLabel();
        labelChefeTecnico1 = new javax.swing.JLabel();
        labelSede1 = new javax.swing.JLabel();
        labelPneus1 = new javax.swing.JLabel();
        labelChassi1 = new javax.swing.JLabel();
        labelMotor1 = new javax.swing.JLabel();
        labelPrimeiraTemporada1 = new javax.swing.JLabel();
        labelCampeaoMundialConstrutores1 = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida1 = new javax.swing.JLabel();
        labelPolePosition1 = new javax.swing.JLabel();
        labelVoltasMaisRapidas1 = new javax.swing.JLabel();
        labelPontos1 = new javax.swing.JLabel();
        tabPanelPilotosEquipe = new javax.swing.JPanel();
        panelPilotosCadastrados = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listPilotosCadastrados = new javax.swing.JList();
        panelPilotosVinculados = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listPilotosVinculados = new javax.swing.JList();
        buttonVincularPiloto = new javax.swing.JButton();
        buttonDesvincularPiloto = new javax.swing.JButton();
        panelEquipesCadastradas = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        listEquipes = new javax.swing.JList();
        panelBotoes = new javax.swing.JPanel();
        buttonSalvar = new javax.swing.JButton();
        buttonAtualizar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Gerenciar Equipes da Temporada");
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        panelTitulo.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        labelTitulo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        labelTitulo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelTitulo.setText("Tela utilizada para gerenciar as equipes da temporada");

        javax.swing.GroupLayout panelTituloLayout = new javax.swing.GroupLayout(panelTitulo);
        panelTitulo.setLayout(panelTituloLayout);
        panelTituloLayout.setHorizontalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(418, Short.MAX_VALUE))
        );
        panelTituloLayout.setVerticalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDadosPrincipais.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Dados Principais   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        labelNomeCompleto.setText("Nome Completo:");

        labelNome.setText("Nome:");

        labelDiretor.setText("Diretor:");

        labelChefeTecnico.setText("Chefe Técnico:");

        labelSede.setText("Sede:");

        labelPneus.setText("Pneus:");

        labelChassi.setText("Chassi:");

        labelMotor.setText("Motor:");

        labelPrimeiraTemporada.setText("Primeira temporada:");

        labelCampeaoMundialConstrutores.setText("Campeonatos mundiais:");

        labelMelhorPosicaoCorrida.setText("Melhor posição em corrida:");

        labelPolePosition.setText("Pole Position:");

        labelVoltasMaisRapidas.setText("Voltas mais rápidas:");

        labelPontos.setText("Pontos:");

        labelNomeCompleto1.setText("Valores");

        labelNome1.setText("Valores");

        labelDiretor1.setText("Valores");

        labelChefeTecnico1.setText("Valores");

        labelSede1.setText("Valores");

        labelPneus1.setText("Valores");

        labelChassi1.setText("Valores");

        labelMotor1.setText("Valores");

        labelPrimeiraTemporada1.setText("Valores");

        labelCampeaoMundialConstrutores1.setText("Valores");

        labelMelhorPosicaoCorrida1.setText("Valores");

        labelPolePosition1.setText("Valores");

        labelVoltasMaisRapidas1.setText("Valores");

        labelPontos1.setText("Valores");

        javax.swing.GroupLayout tabPanelInformacoesEquipeLayout = new javax.swing.GroupLayout(tabPanelInformacoesEquipe);
        tabPanelInformacoesEquipe.setLayout(tabPanelInformacoesEquipeLayout);
        tabPanelInformacoesEquipeLayout.setHorizontalGroup(
            tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabPanelInformacoesEquipeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNomeCompleto)
                    .addComponent(labelNome)
                    .addComponent(labelDiretor)
                    .addComponent(labelChefeTecnico)
                    .addComponent(labelSede)
                    .addComponent(labelPneus)
                    .addComponent(labelChassi)
                    .addComponent(labelMotor)
                    .addComponent(labelPrimeiraTemporada)
                    .addComponent(labelCampeaoMundialConstrutores)
                    .addComponent(labelMelhorPosicaoCorrida)
                    .addComponent(labelPolePosition)
                    .addComponent(labelVoltasMaisRapidas)
                    .addComponent(labelPontos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPontos1)
                    .addComponent(labelVoltasMaisRapidas1)
                    .addComponent(labelPolePosition1)
                    .addComponent(labelMelhorPosicaoCorrida1)
                    .addComponent(labelCampeaoMundialConstrutores1)
                    .addComponent(labelPrimeiraTemporada1)
                    .addComponent(labelMotor1)
                    .addComponent(labelChassi1)
                    .addComponent(labelPneus1)
                    .addComponent(labelSede1)
                    .addComponent(labelChefeTecnico1)
                    .addComponent(labelDiretor1)
                    .addComponent(labelNome1)
                    .addComponent(labelNomeCompleto1))
                .addContainerGap(326, Short.MAX_VALUE))
        );
        tabPanelInformacoesEquipeLayout.setVerticalGroup(
            tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabPanelInformacoesEquipeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNomeCompleto)
                    .addComponent(labelNomeCompleto1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNome)
                    .addComponent(labelNome1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelDiretor)
                    .addComponent(labelDiretor1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelChefeTecnico)
                    .addComponent(labelChefeTecnico1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelSede)
                    .addComponent(labelSede1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPneus)
                    .addComponent(labelPneus1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelChassi)
                    .addComponent(labelChassi1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelMotor)
                    .addComponent(labelMotor1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPrimeiraTemporada)
                    .addComponent(labelPrimeiraTemporada1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelCampeaoMundialConstrutores)
                    .addComponent(labelCampeaoMundialConstrutores1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelMelhorPosicaoCorrida)
                    .addComponent(labelMelhorPosicaoCorrida1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPolePosition)
                    .addComponent(labelPolePosition1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelVoltasMaisRapidas)
                    .addComponent(labelVoltasMaisRapidas1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tabPanelInformacoesEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPontos)
                    .addComponent(labelPontos1))
                .addContainerGap(110, Short.MAX_VALUE))
        );

        pageControlDadosEquipes.addTab("Informações", tabPanelInformacoesEquipe);

        panelPilotosCadastrados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Cadastrados   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        jScrollPane2.setViewportView(listPilotosCadastrados);

        javax.swing.GroupLayout panelPilotosCadastradosLayout = new javax.swing.GroupLayout(panelPilotosCadastrados);
        panelPilotosCadastrados.setLayout(panelPilotosCadastradosLayout);
        panelPilotosCadastradosLayout.setHorizontalGroup(
            panelPilotosCadastradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
        );
        panelPilotosCadastradosLayout.setVerticalGroup(
            panelPilotosCadastradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2)
        );

        panelPilotosVinculados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Vinculados   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        jScrollPane3.setViewportView(listPilotosVinculados);

        javax.swing.GroupLayout panelPilotosVinculadosLayout = new javax.swing.GroupLayout(panelPilotosVinculados);
        panelPilotosVinculados.setLayout(panelPilotosVinculadosLayout);
        panelPilotosVinculadosLayout.setHorizontalGroup(
            panelPilotosVinculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
        );
        panelPilotosVinculadosLayout.setVerticalGroup(
            panelPilotosVinculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3)
        );

        buttonVincularPiloto.setText(">>");
        buttonVincularPiloto.setToolTipText("Vincular piloto selecionado");
        buttonVincularPiloto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVincularPilotoActionPerformed(evt);
            }
        });

        buttonDesvincularPiloto.setText("<<");
        buttonDesvincularPiloto.setToolTipText("Desvincular piloto selecionado");
        buttonDesvincularPiloto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonDesvincularPilotoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tabPanelPilotosEquipeLayout = new javax.swing.GroupLayout(tabPanelPilotosEquipe);
        tabPanelPilotosEquipe.setLayout(tabPanelPilotosEquipeLayout);
        tabPanelPilotosEquipeLayout.setHorizontalGroup(
            tabPanelPilotosEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tabPanelPilotosEquipeLayout.createSequentialGroup()
                .addComponent(panelPilotosCadastrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(tabPanelPilotosEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonVincularPiloto, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buttonDesvincularPiloto, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelPilotosVinculados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        tabPanelPilotosEquipeLayout.setVerticalGroup(
            tabPanelPilotosEquipeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPilotosCadastrados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelPilotosVinculados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(tabPanelPilotosEquipeLayout.createSequentialGroup()
                .addGap(145, 145, 145)
                .addComponent(buttonVincularPiloto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonDesvincularPiloto)
                .addContainerGap(198, Short.MAX_VALUE))
        );

        pageControlDadosEquipes.addTab("Vincular Pilotos", tabPanelPilotosEquipe);

        panelEquipesCadastradas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Equipes   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N
        panelEquipesCadastradas.setPreferredSize(new java.awt.Dimension(232, 152));

        listEquipes.setToolTipText("Lista de equipes cadastradas");
        listEquipes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listEquipesValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(listEquipes);

        javax.swing.GroupLayout panelEquipesCadastradasLayout = new javax.swing.GroupLayout(panelEquipesCadastradas);
        panelEquipesCadastradas.setLayout(panelEquipesCadastradasLayout);
        panelEquipesCadastradasLayout.setHorizontalGroup(
            panelEquipesCadastradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
        );
        panelEquipesCadastradasLayout.setVerticalGroup(
            panelEquipesCadastradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4)
        );

        javax.swing.GroupLayout panelDadosPrincipaisLayout = new javax.swing.GroupLayout(panelDadosPrincipais);
        panelDadosPrincipais.setLayout(panelDadosPrincipaisLayout);
        panelDadosPrincipaisLayout.setHorizontalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                .addComponent(pageControlDadosEquipes, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(panelEquipesCadastradas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        panelDadosPrincipaisLayout.setVerticalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pageControlDadosEquipes)
            .addComponent(panelEquipesCadastradas, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
        );

        panelBotoes.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        buttonSalvar.setText("Salvar");
        buttonSalvar.setToolTipText("Clique para salvar os dados digitados");
        buttonSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSalvarActionPerformed(evt);
            }
        });

        buttonAtualizar.setText("Atualizar");
        buttonAtualizar.setToolTipText("Clique para salvar os dados digitados");
        buttonAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAtualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotoesLayout = new javax.swing.GroupLayout(panelBotoes);
        panelBotoes.setLayout(panelBotoesLayout);
        panelBotoesLayout.setHorizontalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonAtualizar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonSalvar)
                .addContainerGap())
        );

        panelBotoesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAtualizar, buttonSalvar});

        panelBotoesLayout.setVerticalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonSalvar)
                    .addComponent(buttonAtualizar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelBotoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonVincularPilotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVincularPilotoActionPerformed
        // TODO add your handling code here:
        if(this.listPilotosCadastrados.getSelectedIndex() != -1){
            Driver driver = Library.returnDriver( (String)this.listPilotosCadastrados.getSelectedValue());
            if(driver != null){
                try{
                    this.team.hireDriver(driver);
                }catch (IllegalArgumentException e){
                    JOptionPane.showMessageDialog(this, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
        driversLinkedList();
        Library.indexedListDrivers(this.listPilotosCadastrados, FrameMain.getDrivers(), null, true);
    }//GEN-LAST:event_buttonVincularPilotoActionPerformed

    private void buttonDesvincularPilotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDesvincularPilotoActionPerformed
        // TODO add your handling code here:
        if(this.listPilotosVinculados.getSelectedIndex() != -1){
            Driver driver = Library.returnDriver( (String)this.listPilotosVinculados.getSelectedValue());
            if(driver != null){
                this.team.dismissDriver(driver);
            }
        }
        driversLinkedList();
        Library.indexedListDrivers(this.listPilotosCadastrados, FrameMain.getDrivers(), null, true);
    }//GEN-LAST:event_buttonDesvincularPilotoActionPerformed

    private void listEquipesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listEquipesValueChanged
        // TODO add your handling code here:
        if(this.listEquipes.getSelectedIndex() != -1){
            Team team = Library.returnTeam( (String)this.listEquipes.getSelectedValue());
            if(team != null){
                this.team = team;
            }
        }
        dataShowObject();
    }//GEN-LAST:event_listEquipesValueChanged

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_formComponentShown

    private void buttonSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSalvarActionPerformed
        // TODO add your handling code here:
        try{
            checkFields();

            createObject();

            clearFields();
        }catch(IllegalArgumentException e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_buttonSalvarActionPerformed

    private void buttonAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAtualizarActionPerformed
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_buttonAtualizarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAtualizar;
    private javax.swing.JButton buttonDesvincularPiloto;
    private javax.swing.JButton buttonSalvar;
    private javax.swing.JButton buttonVincularPiloto;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JLabel labelCampeaoMundialConstrutores;
    private javax.swing.JLabel labelCampeaoMundialConstrutores1;
    private javax.swing.JLabel labelChassi;
    private javax.swing.JLabel labelChassi1;
    private javax.swing.JLabel labelChefeTecnico;
    private javax.swing.JLabel labelChefeTecnico1;
    private javax.swing.JLabel labelDiretor;
    private javax.swing.JLabel labelDiretor1;
    private javax.swing.JLabel labelMelhorPosicaoCorrida;
    private javax.swing.JLabel labelMelhorPosicaoCorrida1;
    private javax.swing.JLabel labelMotor;
    private javax.swing.JLabel labelMotor1;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelNome1;
    private javax.swing.JLabel labelNomeCompleto;
    private javax.swing.JLabel labelNomeCompleto1;
    private javax.swing.JLabel labelPneus;
    private javax.swing.JLabel labelPneus1;
    private javax.swing.JLabel labelPolePosition;
    private javax.swing.JLabel labelPolePosition1;
    private javax.swing.JLabel labelPontos;
    private javax.swing.JLabel labelPontos1;
    private javax.swing.JLabel labelPrimeiraTemporada;
    private javax.swing.JLabel labelPrimeiraTemporada1;
    private javax.swing.JLabel labelSede;
    private javax.swing.JLabel labelSede1;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JLabel labelVoltasMaisRapidas;
    private javax.swing.JLabel labelVoltasMaisRapidas1;
    private javax.swing.JList listEquipes;
    private javax.swing.JList listPilotosCadastrados;
    private javax.swing.JList listPilotosVinculados;
    private javax.swing.JTabbedPane pageControlDadosEquipes;
    private javax.swing.JPanel panelBotoes;
    private javax.swing.JPanel panelDadosPrincipais;
    private javax.swing.JPanel panelEquipesCadastradas;
    private javax.swing.JPanel panelPilotosCadastrados;
    private javax.swing.JPanel panelPilotosVinculados;
    private javax.swing.JPanel panelTitulo;
    private javax.swing.JPanel tabPanelInformacoesEquipe;
    private javax.swing.JPanel tabPanelPilotosEquipe;
    // End of variables declaration//GEN-END:variables

    //Metodos reescritos da interface InterfaceRegister
    @Override
    public void dataShowObject() {
        this.labelNomeCompleto1.setText(this.team.getFullName());
        this.labelNome1.setText(this.team.getShortName());
        this.labelDiretor1.setText(this.team.getTeamPrincipal());
        this.labelChefeTecnico1.setText(this.team.getTechinicalChief());
        this.labelSede1.setText(this.team.getBase());
        this.labelPneus1.setText(this.team.getTyres());
        this.labelChassi1.setText(this.team.getChassis());
        this.labelMotor1.setText(this.team.getEngine());
        this.labelPrimeiraTemporada1.setText(""+this.team.getFirstSeason());
        this.labelCampeaoMundialConstrutores1.setText(""+this.team.getWorldChampionchips());
        this.labelMelhorPosicaoCorrida1.setText(this.team.getHighestRaceFinish()[0]+" (x"+this.team.getHighestRaceFinish()[1]+")");
        this.labelPolePosition1.setText(""+this.team.getPolePositions());
        this.labelVoltasMaisRapidas1.setText(""+this.team.getFastesLaps());
        this.labelPontos1.setText(""+this.team.getPoints());

        Library.indexedListDrivers(this.listPilotosCadastrados, FrameMain.getDrivers(), null, true);
        driversLinkedList();
        Library.indexedListTeams(this.listEquipes, null, FrameMain.getSeasonLoaded());
    }

    @Override
    public void checkFields() throws IllegalArgumentException {
        
    }

    @Override
    public void checkValueEntered() throws IllegalArgumentException, ParseException {
        
    }

    @Override
    public void createObject() throws IllegalArgumentException {
        ManagementFilesSeason.writeHireDriverSeason(FrameMain.getSeasonLoaded(), FrameMain.getFolderSeasonLoaded());
    }

    @Override
    public void clearFields(){
        this.team = new Team();

        this.listEquipes.setSelectedIndex(0);

        dataShowObject();
        this.labelTitulo.setText("Tela utilizada para gerenciar as equipes da temporada de "+FrameMain.getSeasonLoaded().getYear());
        Library.indexedListDrivers(this.listPilotosCadastrados, FrameMain.getDrivers(), null, true);
        Library.indexedListTeams(this.listEquipes, null, FrameMain.getSeasonLoaded());
    }
}
